﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;

using MicroCenter.Models;
using MicroCenter.Services;

using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

using Utils;

namespace MicroCenter.Controllers
{
    [Auth]
    [Route("api/[controller]")]
    [ApiController]
    public class NginxController : ControllerBase
    {
        public readonly NginxService nginxService;

        [Get]
        public bool IsRun()
        {
            return nginxService.IsRun();
        }

        [Get]
        public void InstallConfig()
        {
            nginxService.InstallConfig();
        }

        [Get]
        public void RunCmd(string cmd)
        {
            switch (cmd)
            {
                case "start":
                    nginxService.Start();
                    break;
                case "stop":
                    nginxService.Stop();
                    break;
                case "reload":
                    nginxService.Reload();
                    break;
                default:
                    throw Error.DefaultError("无效指令");
            }
        }

    }
}
